package com.example.demo.controller;

import com.example.demo.model.Response;
import com.example.demo.model.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {
    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/test_Controller")
    public Response<String> testController(@RequestBody Test test) {
        Response<String> response=new Response<>();
        try{
             response.setData(restTemplate.postForObject("http://localhost:8081/add_test", test, String.class));
        }catch(RuntimeException e){
            response.setErrorNo(-1);
            response.setErrorMessage(e.getMessage());
        }
        return response;
    }
}
